// 测试会员注册功能
const { registerMember } = require('../models/Member');
const bcrypt = require('bcryptjs');

describe('Member Registration', () => {
  it('should hash password before saving', (done) => {
    registerMember('测试用户', 'test@example.com', 'password123', '13800138000', (err, result) => {
      bcrypt.compare('password123', result.password, (err, isMatch) => {
        expect(isMatch).toBe(true);
        done();
      });
    });
  });
});

// 测试JWT生成
const jwt = require('jsonwebtoken');
process.env.JWT_SECRET = 'test-secret';

describe('JWT Authentication', () => {
  it('should generate valid token', () => {
    const token = jwt.sign({ userId: 1 }, process.env.JWT_SECRET);
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    expect(decoded.userId).toBe(1);
  });
});